package com.example.zg3_park.User

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.lib_base.mvvm.BaseActivity
import com.example.zg3_park.R
import com.example.zg3_park.databinding.ActivityRegisterBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class RegisterActivity : BaseActivity<ActivityRegisterBinding,UserViewModel>() {

    override fun intiView() {
        binding.btnRegister.setOnClickListener {
            val name = binding.loginUname.text.toString()
            val pwd = binding.loginPass.text.toString()

            if(name.isNullOrEmpty() || pwd.isNullOrEmpty()) {
                ToastUtils.showLong("不能为空")
                return@setOnClickListener
            }

            if(!name.matches(Regex("[A-z0-9_]{2,8}"))) {
                ToastUtils.showLong("不是合法用户名")
                return@setOnClickListener
            }

            //两次密码一致问题
            if(!binding.loginPass.text.toString().equals(binding.loginRepass.text.toString())) {
                ToastUtils.showLong("两次密码不一致")
            }
            vm.register(name,pwd)
        }
    }

    override fun intiData() {
        vm.registerData.observe(this) {
            Log.i("lr",it.toString())
            ARouter.getInstance().build("/app/LoginActivity").navigation()
        }
    }
}